package hotLeetcode;

import java.util.Stack;

public class H155Leetcode {


    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(1);
        minStack.push(2);
        minStack.push(1);
        minStack.pop();
        minStack.pop();
        minStack.pop();
    }
}


class MinStack {

    private Stack<Integer> stack;
    private Stack<Integer> min_stack;


    public MinStack() {
        stack = new Stack<>();
        min_stack = new Stack<>();



    }

    public void push(int val) {
        stack.push(val);
        if (min_stack.isEmpty() || min_stack.peek() >= val) {
            min_stack.push(val);
        }

    }

    public void pop() {
        if (stack.pop().equals(min_stack.peek())) {
            min_stack.pop();
        }



    }

    public int top() {
        return stack.peek();

    }

    public int getMin() {
        return min_stack.peek();
    }




}